package org.sdp.pearproject.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;
import org.sdp.pearproject.dao.domain.*;
import org.sdp.pearproject.service.*;
import org.sdp.pearproject.service.custom.*;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

/**
 * @ClassName: MemberServiceImpl
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-18
 * @Version: 1.0
 * Table: pear_member
 * Comment:
 * 用户表
 */
@Service
public class MemberServiceImpl extends MemberServiceCustomImpl implements MemberService {

    static {
        beanClassNameMap.put("member", "memberServiceImpl");
        listMethodNameMap.put("member", "listMember");
        listMethodParameterClassNameMap.put("member", "MemberQueryRequest");
        updateMethodNameMap.put("member", "updateMember");
        updateMethodParameterClassNameMap.put("member", "MemberUpdateRequest");
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer addMember(MemberAddRequest request) throws Exception {
        super.fixRequest("member", "add", request);
        return super.addMember(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateMember(MemberUpdateRequest request) throws Exception {
        Member record = null;
        record = memberMapper.selectByPrimaryKey(request.getId());
        super.fixRequest("member", "update", request, record);
        return super.updateMember(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteMember(MemberDeleteRequest request) throws Exception {
        if (needCheckDeleteList(request)) {
            List<Member> list = null;
            MemberExample example = new MemberExample();
            example.createCriteria().andIdIn(request.getIdList());
            list = memberMapper.selectByExample(example);
            fixRequest("member", "delete", request, list);
        } else {
            fixRequest("member", "delete", request);
        }
        return super.deleteMember(request);
    }

    @Override
    public MemberQueryResponse queryMember(MemberQueryRequest request) throws Exception {
        super.checkNonNull(request.getId(), "系统前台用户表");
        MemberQueryResponse result = super.queryMember(request);
        checkResult("member", "query", request, result);
        return result;
    }

    @Override
    public List<MemberQueryResponse> listMember(MemberQueryRequest request) throws Exception {
        List<MemberQueryResponse> list = super.listMember(request);
        checkResult("member", "list", request, list);
        return list;
    }

    @Override
    public Integer countMember(MemberQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("member", "count", request);
        return super.countMember(request);
    }

    @Override
    public BaseStatResponse statMember(MemberQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("member", "stat", request);
        return super.statMember(request);
    }

}
